/**
 * 
 */
package com.jm.web.form.table;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.jsp.JspWriter;

import com.jm.web.form.support.FormItem;

/**
 * @author yanjie
 *
 * 2011/9/22 下午1:31:45
 */
public class Tr extends FormItem{
	public final static String TAG_ITEMNAME = "TR";
	protected List tds = null ;
	protected String trBeginHtml = "";//合并單元格時候使用
	protected String trEndHtml = "";//合并單元格時候使用
	
	/**
	 * @param tag
	 */
	public Tr() {}
	
	@Override
	public void onOutItemBegin(JspWriter writer) {
		super.onOutItemBegin(writer);
	}
	
	@Override
	public void onOutItemEnd(JspWriter writer) {
		super.onOutItemEnd(writer);
	}

	public void outHtml(JspWriter out,String stripeClass) {
		try {
			out.write(this.getTrBeginHtml());
			
			if(stripeClass.length() > 0){
				
				out.write(" class = \""+stripeClass+"\" ");
			}
			
			
			out.write(">");
			if(this.getTds() != null){
				for (int i = 0; i < this.getTds().size(); i++) {
					((Td)this.getTds().get(i)).outHtml(out);
				}
			}
			out.write(this.getTrEndHtml());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public List getTds() {
		return tds;
	}
	
	public void addTd(Td td){
		if(this.getTds() == null)
			this.tds = new ArrayList();
		this.tds.add(td);
	}
	
	public String getTrBeginHtml() {
		return trBeginHtml;
	}

	public void setTrBeginHtml(String trBeginHtml) {
		this.trBeginHtml = trBeginHtml;
	}

	public String getTrEndHtml() {
		return trEndHtml;
	}

	public void setTrEndHtml(String trEndHtml) {
		this.trEndHtml = trEndHtml;
	}

	public Td getLastTd() {
		if(this.tds == null || this.tds.size() == 0)
			return null;
		return (Td)this.tds.get(this.tds.size() - 1);
	}
	
	
	
}
